# Maintainer: Frederik Schwan <freswa at archlinux dot org>
# Contributor: Chris Lane <aur at chrislane dot com>
# Contributor: phiresky <phireskyde+aur@gmail.com>
# Contributor: Julien Nicoulaud <julien DOT nicoulaud AT gmail DOT com>

pkgname=ripgrep-all
pkgver=0.9.6
pkgrel=4
pkgdesc="rga: ripgrep, but also search in PDFs, E-Books, Office documents, zip, tar.gz, etc."
arch=('loong64' 'x86_64')
url='https://github.com/phiresky/ripgrep-all'
license=('AGPL3')
depends=('ripgrep' 'xz')
makedepends=('cargo')
optdepends=(
  'ffmpeg: for the ffmpeg adapter'
  'graphicsmagick: for the pdfpages adapter'
  'pandoc: for the pandoc adapter'
  'poppler: for the poppler adapter'
  'tesseract: for the tesseract adapter'
)
options=(!lto)
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/phiresky/ripgrep-all/archive/refs/tags/v${pkgver}.tar.gz"
        pandoc_compat.patch)
b2sums=('184ad8835c00913eba07c6f922683b372f790ba9a04141bb98fa7510095cc392b750361ddd0cbe0e2ebf832b24249c0203f07b1e494ae7810ca1585868895bf2'
        '1d794aff3883999acd69c26151d8c956dfe4df38ddff2919c7a7e24955682b9af5638db6b0a32752348216a46ffd73c15cd7f4f71b6f5d8f9eed6adc6f8e2968')

prepare() {
  cd ripgrep-all-${pkgver}
  # Pandoc 3.x compatibility
  patch -Np1 < ../pandoc_compat.patch
  cargo fetch --locked --target "$CARCH-unknown-linux-gnu"
}

build() {
  cd ripgrep-all-${pkgver}
  export RUSTUP_TOOLCHAIN=stable
  export CARGO_TARGET_DIR=target
  cargo build --frozen --release --all-features
}

check() {
  cd ripgrep-all-${pkgver}
  export RUSTUP_TOOLCHAIN=stable
  cargo test --frozen --all-features
}

package() {
  cd ripgrep-all-${pkgver}
  install -Dm 755 target/release/rga "${pkgdir}"/usr/bin/rga
  install -Dm 755 target/release/rga-preproc "${pkgdir}"/usr/bin/rga-preproc
}
